What is @sinonjs/samsam?
The @sinonjs/samsam package is a library designed for deep comparison and matching of objects, arrays, and other JavaScript data types. It is particularly useful in the context of testing, where developers need to assert the equality of complex objects and arrays.
What are @sinonjs/samsam's main functionalities?
Deep equality
This feature allows for the deep comparison of objects, arrays, and other complex data structures to determine if they are equal in structure and content.
const samsam = require('@sinonjs/samsam');
const obj1 = { a: 1, b: { c: 2 } };
const obj2 = { a: 1, b: { c: 2 } };
console.log(samsam.deepEqual(obj1, obj2)); // outputs: true
Match object properties
This functionality enables matching objects against specified criteria, useful for asserting the presence of certain properties or property values within an object.
const samsam = require('@sinonjs/samsam');
const obj = { a: 1, b: 2 };
console.log(samsam.match(obj, { a: 1 })); // outputs: true
Other packages similar to @sinonjs/samsam
chai
Chai is a BDD / TDD assertion library for node and the browser that can be delightfully paired with any javascript testing framework. It offers similar deep equality assertions and matchers but with a more extensive plugin ecosystem and chainable methods, providing a more flexible and expressive approach compared to @sinonjs/samsam.
deep-equal
This package provides a simple and straightforward implementation of deep equality comparison. While it covers the basic need of deep equality checks, it lacks the additional matching capabilities and custom assertions provided by @sinonjs/samsam.